﻿<?php

$stdstyle = 'style="font-family: Verdana; font-size: 12pt"';

function html_open ($title='No Title', $style='') {
	$style = ($style=='') ? $GLOBALS['stdstyle'] : 'style="'.$style.'"' ;
	return "<html><head><title>$title</title></head><body $style>";
}

function html_close () {
	return '</body></html>';
}

function form_open ($title='No Title', $fname='myform', $action='', $method='post', $style='', $onload='') {
	$style = ($style=='') ? $GLOBALS['stdstyle'] : 'style="'.$style.'"' ;
	$action = ($action=='') ? $GLOBALS['PHP_SELF'] : $action;
	return "<html><head><title>$title</title></head><form name='$fname' action='$action' method='$method' $style $onload>";
}

function form_close () {
	return '</form></html>';
}

function text_box ($name='textbox', $value='', $size='', $maxlengh='', $style='') {
	$style = ($style=='') ? $GLOBALS['stdstyle'] : 'style="'.$style.'"' ;
	$maxlength = ($maxlength=='') ? '' : "maxlength='$maxlengh'" ;
	$size = ($size=='') ? '' : "size='$size'" ;
	$value = ($value=='') ? '' : "value='$value'" ;
	return "<input type='text' name='$name' $value $size $maxlengh $style>";
}

function cmd ($value='Ok', $name='cmd', $id='id', $style='') {
	$style = ($style=='') ? $GLOBALS['stdstyle'] : 'style="'.$style.'"' ;
	return "<input type='submit' name='$name' id='$id' value='$value' $style>&nbsp;";
}

function cb ($name='cb', $value='1', $currentvalue='') { 
	$checked = ($value==$currentvalue)? 'checked' : '';
	return "<input type = 'checkbox' name = '$name' value = '$value' $checked>";
}

function rb ($name='rb', $value='1', $currentvalue='', $onclick='') {
	$checked = ($value==$currentvalue)? 'checked' : '';
	$onclick = ($onclick=='') ? '' : "onclick='$onclick'";
	return "<input type = 'radio' name='$name' value='$value' $checked $onclick>";
}

function tbl_open ($width='100%', $border='0', $cellspacing='0', $cellpadding='2', $style='') {
	$style = ($style=='') ? $GLOBALS['stdstyle'] : 'style="'.$style.'"' ;
	return "<table width='$width' border='$border' cellspacing='$cellspacing' cellpadding='cellpadding' style='$style'>";
}

function tbl_close() {
	return '</table>';
}

function td ($value='&nbsp', $width='', $align='', $colspan='', $rowspan='', $valign='') {
	$width = ($width=='')? '' : "width='$width'";
	$colspan = ($colspan=='')? '' : "colspan='$colspan'";
	$rowspan = ($rowspan=='')? '' : "rowspan='$rowspan'";
	$align = ($align=='')? '' : "align='$align'";
	$valign = ($valign=='')? '' : "valign='$valign'";
	return "<td $width $colspan $rowspan $align $valign>$value</td>";
}

function tr ($value, $align='') {
	$align = ($align=='')? '' : " align='$align'";
	return "<tr $align>$value</tr>";
}

function stdName ($astr) {
// Chuẩn hóa xâu $astr theo định dạng tên người, tên địa danh
	$retval = $astr;
	
	// $astr ==> $retval

	return $retval;
}

function listbox ($name='lb', $valuefield, $dispfield, $tblname='', $currentvalue='', $style='', $onchange='') {
	$retval = '';
	$style = ($style=='') ? $GLOBALS['stdstyle'] : 'style="'.$style.'"' ;
	$onchange = ($onchange=='') ? '' : "onchange='$onchange'";
	if ($tblname!='') {
		$result = mysql_query ("select $valuefield, $dispfield from $tblname order by $valuefield");
		$retval = "<select name='$name' $style $onchange>";
		if (mysql_num_rows($result) == 0)
			$retval .= '<option value="">No selection</option>';
		else {
			while ($row=mysql_fetch_array($result))
				$retval .= '<option value="'.$row[$valuefield].'"'. (($row[$valuefield]==$currentvalue)? ' selected' : '') . '>' . $row[$dispfield].'</option>';
		}
		$retval .= '</select>';
	} else 
		$retval = "<select name='$name' $style $onchange><option value=''>No table for selections</option></select>";
	return $retval;
}
?>
















